<?php

declare(strict_types=1);

namespace Upside\Router;

use Upside\Std\Option;
use function Upside\Std\None;
use function Upside\Std\Some;

final class Router implements RouterInterface
{
    private RouteCollector $route_collector;

    public function __construct(RouteCollector $route_collector)
    {
        $this->route_collector = $route_collector;
    }

    /**
     * @return Option<Route>|Option<null>
     */
    public function match(string $path): Option
    {
        foreach ($this->route_collector->get_routes() as $route) {
            if ($route->path === $path) {
                return Some($route);
            }
        }

        return None();
    }
}
